<?php
include('../DBManager/LibUser.php');
session_start();

$user = LibUser::findLibUser($_POST['usr']);
// If the user entered an invalid username or password, redirect to the login
// page and notify the mistake
if($user == null || ($_POST['pssw'] != $user->getPssw())){
    $_SESSION['notLogin'] = 1;
?>
    <script type='text/javascript'>
        window.location='login.php';
    </script>
<?php
}

//Else set the session and redirect to the homepage
$_SESSION['login'] = $user->getLogin();
$_SESSION['userName'] = $user->getName();
$_SESSION['userLastName'] = $user->getLastName();
?>
<script type='text/javascript'>
    window.location='../home.php';
</script>
